package com.itstudy.mapper;

import com.itstudy.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    /**
     * 查询所有用户
     * @return
     */
    //@Select("select * from user")
    public List<User> findAll();
    /**
     * 根据id删除用户
     * @param id
     */
    @Delete("delete from user where id=#{id}")
    public Integer deleteById(Integer id);
    /**
     * 添加用户
     * @param user
     */
    @Insert("insert into user(username,password,name,age) values(#{username},#{password},#{name},#{age})")
    public void insertUser(User user);

    /**
     * 更新用户
     * @param user
     */
    @Update("update user set username=#{username},password=#{password},name=#{name},age=#{age} where id=#{id}")
    public void updateUser(User user);

    /**
     * 根据用户名和密码查询用户
     * select使用的#{写的是param定义的名字}
     * @param username
     * @param password
     * @return
     */
    @Select("select * from user where username=#{username} and password=#{password}")
    public User findByUsernameAndPassword(@Param("username") String username, @Param("password") String password);
}
